  <?php form_head("admin/search","") ?>
	<?php 
		 
	$filter = $this->session->userdata("filter");
	$condition =  "";
	if($filter["category_id"])
	{
		
		$condition .=" and  category_id =".$filter["category_id"];
	}
	if($filter["company_id"])
	{
		
		$condition .=" and  company_id =".$filter["company_id"];
	}
	if($filter["budget_id"])
	{
		
		$condition .=" and  budget_id =".$filter["budget_id"];
	}
	if($filter["type_id"])
	{
		
		$condition .=" and  type_id =".$filter["type_id"];
	}
	?>
	
	<?php 
	
		

		 $rows =  $this->db->get("material_types")->result_array();
		 select_field("type_id","ดูรายงานตาม ชนิด",$rows,"type_name",0,0,"All",1,null,"",2); 
		 
	?>
	
	<?php 
	
	$sql = "SELECT  CONCAT( meterial_base_categories.cat_base_name,'|',material_categories.category_name) as category_name,
		      material_categories.category_id, 
		      	meterial_base_categories.sort_order
		      FROM meterial_base_categories INNER JOIN material_categories ON meterial_base_categories.cat_base_id = material_categories.cat_base_id
			
		      order by sort_order asc";

		 $rows =  $this->db->query($sql)->result_array();
		 select_field("category_id","ดูรายงานตาม หมวดวัสดุ-ครุภัณฑ์",$rows,"category_name",0,0,"All",1,null,"",2); 
		 ?>
		 	      
		 
		 <?php 
		 $rows =  $this->db->query("select budget_id, concat(budget_name,'-', year) as budget_name from budgets")->result_array();
		 select_field("budget_id","ดูรายงานตาม งบประมาณ/ปีการศึกษา",$rows,"budget_name",0,0,"All",0,null,"",2); 
		//select_field($name,$label,$rows,$label_value,$row,$cleaner = 0,$first_label="โปรดเลือก",$class ="",$type=1)
		 ?>
         <?php 
		 $rows =  $this->db->query("select company_id,concat(company_name,'')as company_name from company")->result_array();
		 select_field("company_id","บริษัทจัดหา",$rows,"company_name",0,0,"All",null,"",2); 
		 ?>
	<?php form_footer("Filter"); ?>
   <?php $rows = $this->db->query("select * from inventory_views where 1 $condition ")->result_array() ?> 
 
   <table class="list">
   <thead>
   <th>เลขที่ลงทะเบียน</th>
   <th>วันที่ลงทะเบียน</th>
   <th>ชื่อวัสดุ-ครุภัณฑ์</th>
   <th>หมวด</th>
   <th>จำนวน</th>
   <th>ปีการศึกษา</th>
   <th>ดูรายละเอียด</th>
   </thead>
   <tbody>
  
   	 <?php 
   	 $i = 1;
   	 foreach($rows as $row){ ?>
   	  <tr class="<?php if($i++%2){ echo 'even'; } ?>">
   	  <td><?php echo $row["code"]; ?></td>
      <td><?php echo $row["create_date2"]; ?></td>
      <td><?php echo $row["name"]; ?></td>
      <td><?php echo $row["category_name"]; ?></td>
      <td><?php echo $row["amount_total"]; ?></td>
      <td><?php echo $row["year"]; ?></td>
      <td><a href="<?php echo site_url("admin/material_view/".$row["material_id"]); ?>">เพิ่มเติม</a></td>
     <tr/>
     <?php } ?> 
      </tbody>
   </table>
   <style>
  #content .form .field .left 
   {
   width: 250px
   }
   </style>